import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
import { RoleService } from './role.service';
import { CreateRoleDto } from './dto/create-role.dto';
import { UpdateRoleDto } from './dto/update-role.dto';
import { Result } from '../common/dto/common.result';
import { PageRoleDto } from './dto/page-role.dto';

@Controller('role')
export class RoleController {
  constructor(private readonly roleService: RoleService) { }

  @Post('/save')
  async create(@Body() createRoleDto: CreateRoleDto) {
    await this.roleService.create(createRoleDto);
    return Result.success();
  }

  @Get('/list')
  async findAll() {
    return Result.successData(await this.roleService.findAll());
  }

  @Get('/info/:id')
  async findOne(@Param('id') id: number) {
    return Result.successData(await this.roleService.findOne(id));
  }

  @Patch('/info/:id')
  async update(@Body() updateRoleDto: UpdateRoleDto) {
    await this.roleService.update(updateRoleDto.id, updateRoleDto);
    return Result.success();
  }

  @Delete(':id')
  async remove(@Param('id') id: number) {
    await this.roleService.remove(id);
    return Result.success();
  }

  @Patch('/info/status')
  async changeStatus(@Body() updateRoleDto: UpdateRoleDto) {
    await this.roleService.changeStatus(updateRoleDto.id, updateRoleDto.status);
    return Result.success();
  }

  @Get('/list/page')
  async page(pageRoleDto: PageRoleDto) {
    return Result.successData(await this.roleService.page(pageRoleDto));
  }
}
